// Copyright 2012 Jay Young. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * @fileoverview
 *
 * Simple data structures needed in various algorithms around the project.
 */



/**
 * Simple queue implementation used in breadth-first tree traversal.
 * @constructor
 */
var Q = exports.Q = function() {
  /**
   * Array to use as the queue.
   * @type {Array.<*>}
   * @private
   */
  this.q_ = [];
};


/**
 * Push an item onto the back of the queueu.
 * @param {*} item The thing to push.
 */
Q.prototype.enQ = function(item) {
  this.q_.push(item);
};


/**
 * Retrieve the item at the front of the queue.
 * @return {*} Whatever was at the head (this will be undefined if the queue is
 *    empty).
 */
Q.prototype.deQ = function() {
  return this.q_.shift();
};


/**
 * @return {number} The number of items in the queue.
 */
Q.prototype.length = function() {
  return this.q_.length;
};


/**
 * Simple stack implementation.
 * @constructor
 */
var Stack = exports.Stack = function() {
  /**
   * The array to use as a stack.  We're going to push and pop off the end.
   * @type {Array.<*>}
   * @private
   */
  this.stack_ = [];
};


/**
 * Push an item onto the stack.
 * @param {*} item The thing to push.
 */
Stack.prototype.push = function(item) {
  this.stack_.push(item);
};


/**
 * @return {*} The top item on the stack.
 */
Stack.prototype.pop = function() {
  return this.stack_.pop();
};
